package com.lb.bs.client.processor.handle.dynamics.update;

import com.lb.bs.client.annotation.SingletonMark;
import com.lb.bs.client.beans.LBGrayIPBean;
import com.lb.bs.client.processor.ProcessorHandleService;
import com.lb.bs.client.processor.beans.ProcessorDynamicHandlerBean;
import com.lb.bs.client.repository.StoreCenter;
import com.lb.bs.client.util.CollectionUtils;
import com.lb.bs.client.util.GrayUtil;

import java.util.List;
import java.util.Map;

/**
 * program: LB-BS-Client
 * author: bsworld.xie
 * create: 2019-12-19 17:28
 * description:
 */
@SingletonMark
public class GrayUpdateIPKeyProcessorHandle implements ProcessorHandleService<ProcessorDynamicHandlerBean> {

    @Override
    public void handleProcess(ProcessorDynamicHandlerBean handlerBean) {
        String key = handlerBean.getKey();
        Map<String, LBGrayIPBean> grayItemKeyMap = StoreCenter.getInstance().getGrayIPKeyMap();
        if (CollectionUtils.isEmpty(grayItemKeyMap)) {
            return;
        }
        LBGrayIPBean grayIPBean = grayItemKeyMap.get(key);
        if (grayIPBean == null) {
            return;
        }
        List<String> ipList = GrayUtil.zkIpData2List(handlerBean.getData());
        grayIPBean.setGrayIpList(ipList);
    }
}
